<%@ page import="com.oval.util.JspHelper" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%--Search for an item--%>

<%
 
  OvalSearchAPI osa = new OvalSearchAPI();
  Vector labels = new Vector();
  String module = OvalEncode.GBKToIso(request.getParameter("module"));
  String labelcode = OvalEncode.GBKToIso(request.getParameter("labelcode"));
  String labelname = OvalEncode.GBKToIso(request.getParameter("labelname"));
  String languagecode = OvalEncode.GBKToIso(request.getParameter("languagecode"));
  
  String whereclause = "";
  if(module != null && module.length() != 0)
    whereclause += " and module like '" + module + "'";
  if(labelcode != null && labelcode.length() != 0)
    whereclause += " and labelcode like '" + labelcode + "'";
  if(labelname != null && labelname.length() != 0)
    whereclause += " and labelname like '" + labelname + "'";
  if(languagecode != null && languagecode.length() != 0)
    whereclause += " and languagecode='" + languagecode + "'";
  whereclause += " order by labelcode asc";
  
  if(module != null)
    labels = osa.getSearchResults("ovscreenlabel",whereclause,null,null);
%>
<html>
<head>
<title>e-manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="../css/chinese/script.js"></script>

<%--Check what to do if press the corresponding button--%>

<script language="JavaScript">
function page_search()
{
  frm.actionname.value = "search"; 
  if(isEmpty(frm.module.value))
  {
    <%--[SCRIPT]  alert("Please input module name!");  [SCRIPT]--%>
    <%--[SCRIPT]  return;  [SCRIPT]--%>
  }
  if(!isEmpty(frm.languagecode.value) && frm.languagecode.value != "cn" && frm.languagecode.value != "en"&& frm.languagecode.value != "jp")
  {
    alert("Language Code must be cn/en/jp!");
    return;
  }
  document.frm.submit();
}
function page_add()
{
  self.location.href = "labelAdd.jsp?module=" + frm.module.value;
}
function page_edit()
{
  var checkTimes = 0;
  for(var i=0;i<frm.checkedIds.length;i++)  
  {
    if(frm.checkedIds[i].checked == 1)
    {
      checkTimes = checkTimes + 1;
    }
  }
  if(checkTimes > 3)
  {
    alert("Please only check three box!");
    return;  
  }
  frm.actionname.value = "edit";
  if(isNullChecked(document.frm.checkedIds))
  {
    alert("Choose the edit label,Please!");
    return;
  }
  document.frm.action = "labelEdit.jsp";
  document.frm.submit();
}
function page_delete()
{
  frm.actionname.value = "delete";
  if(isNullChecked(document.frm.checkedIds))
  {
    alert("Choose the delete label,Please!");
    return;
  }
  document.frm.action = "labelAction.jsp";
  document.frm.submit();
}

function clickid(index)
{
   if(frm.checkedIds[0] == null)
   {
   	return;
   }
  var lc = frm.checkedIds[index].labelcode;
  frm.edit_module.value = frm.checkedIds[index].module;
  frm.edit_labelcode.value = frm.checkedIds[index].reallabelcode;
  if(frm.checkedIds[index].languagecode == "en")
  {
    frm.edit_labelnameen.value = frm.checkedIds[index].labelname;
    frm.edit_enid.value = frm.checkedIds[index].labelid;
  }
  else
  {
    frm.edit_labelnamecn.value = frm.checkedIds[index].labelname;
    frm.edit_cnid.value = frm.checkedIds[index].labelid;
  }
  var flag = frm.checkedIds[index].checked;
  for(var i=0;i<frm.checkedIds.length;i++)  
  {
    if(frm.checkedIds[i].labelcode == lc)
    {  
      frm.checkedIds[i].checked = flag;
      if(frm.checkedIds[i].languagecode == "en")
      {	
	frm.edit_labelnameen.value = frm.checkedIds[i].labelname;
	frm.edit_enid.value = frm.checkedIds[i].labelid;
      }
      else if(frm.checkedIds[i].languagecode == "cn")
      {
	frm.edit_labelnamecn.value = frm.checkedIds[i].labelname;
	frm.edit_cnid.value = frm.checkedIds[i].labelid;
      }
      else {
      	frm.edit_labelnamejp.value = frm.checkedIds[i].labelname;
				frm.edit_jpid.value = frm.checkedIds[i].labelid;
      }
    }
  }
}

<%--                            Display First Line    --%> 

</script>
</head>
<body>
<form name="frm" action="labelSummary.jsp">
  <input type="hidden" name="actionname">
  <input type="hidden" name="edit_labelnamecn">
  <input type="hidden" name="edit_labelnameen">
  <input type="hidden" name="edit_labelnamejp">
  <input type="hidden" name="edit_module">
  <input type="hidden" name="edit_labelcode">
  <input type="hidden" name="edit_cnid">
  <input type="hidden" name="edit_enid">
  <input type="hidden" name="edit_jpid">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
 <tr align="center">
  <td>MODULE:</td><td class="input"><input type="text" name="module" size="5" value="<%=JspHelper.filterNull( request.getParameter("module") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>LabelCode:</td><td class="input"><input type="text" name="labelcode" size="10" value="<%=JspHelper.filterNull( request.getParameter("labelcode") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>LabelName:</td><td class="input"><input type="text" name="labelname" size="10" value="<%=JspHelper.filterNull( request.getParameter("labelname") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>LanguageCode:</td><td class="input"><input type="text" name="languagecode" size="3" value="<%=JspHelper.filterNull( request.getParameter("languagecode") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td><input type="button" name="Search" value="Search" onclick="javascript:page_search()"></td>
  <td><input type="button" name="Add" value="Add" onclick="javascript:page_add()"></td>
  <td><input type="button" name="Edit" value="Edit" onclick="javascript:page_edit()"></td>
  <td><input type="button" name="Delete" value="Delete" onclick="javascript:page_delete()"></td>
 </tr>
</table>

<%--Display Second Line--%>

<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
  <tr> 
    <td class="td_title_bg">
      &nbsp;
    </td>
    <td class="td_title_bg">
      Moudule Name
    </td>
    <td class="td_title_bg">
      Label Code
    </td>
    <td class="td_title_bg">
      Label Name
    </td>
     <td class="td_title_bg">
      Language Code
    </td>
  </tr>

<%--Display the items--%>

  <% 
     for(int i=0;i<labels.size();i++)
     {
       HashMap temp = (HashMap)labels.get(i);
  %>
     <tr class="td_bg_row"> 
       <td>
         <div align="center">
          <input type="checkbox" border=0 style="border:0" name="checkedIds" labelcode="<%=JspHelper.filterNull( temp.get("module")+"_"+temp.get("labelcode") )%>" reallabelcode="<%=JspHelper.filterNull( temp.get("labelcode") )%>" module="<%=JspHelper.filterNull( temp.get("module") )%>" languagecode="<%=JspHelper.filterNull( temp.get("languagecode") )%>" labelname="<%=JspHelper.filterNull( temp.get("labelname") )%>" labelid="<%=JspHelper.filterNull( temp.get("labelid") )%>" value="<%=JspHelper.filterNull( temp.get("labelcode") )%>" onclick="javascript:clickid(<%=JspHelper.filterNull( i )%>)">
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("module") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("labelcode") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("labelname") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("languagecode") )%>&nbsp;
         </div>
       </td>
     </tr>
  <% } %>
  
</table>
</form>
</body>
</html>

